<?php
/**
 * Created by PhpStorm.
 * User: 雨寒
 * Date: 2018/12/7
 * Time: 上午8:21
 */
namespace app\admin\controller;

use think\Exception;
use think\Db;
use app\common\model\Message;
class Comment extends Common
{
    //评论列表
    public function index()
    {
        $this->templateTitle('评论列表');

        //判断条件
        $where['gc.id']=['gt',0];


        //搜索条件-用户
        $user_condition = request()->param("user_condition");
        $this->assign("user_condition", $user_condition);
        if ($user_condition)
        {
            $where["us.nick_name|us.mobile|us.id"] = ["LIKE", "%$user_condition%"];
        }

        //搜索条件-商品
        $or_condition = request()->param("g_condition");
        $this->assign("g_condition", $or_condition);
        if ($or_condition)
        {
            $where["g.id|g.title"] = ["LIKE", "%$or_condition%"];
        }

        //获取评价列表
        $list = Db::name("goods_comment")
            ->alias('gc')
            ->join('__USER__ us','us.id=gc.uid','LEFT')
            ->join('__GOODS__ g','g.id=gc.goods_id','LEFT')
            ->where($where)
            ->order("gc.comment_time DESC")
            ->field('gc.*,us.nick_name as uname,us.mobile as umobile,g.title as gtitle,g.img_url as img_url')
            ->paginate(10);
        $this->assign("list", $list);

        return $this->fetch();
    }
    /*删除评论*/
    public function remove_comment()
    {
        if(request()->isAjax())
        {
            $id=input('id');
            if(empty($id)){
                $this->ajaxError("参数错误");
            }
            /*删除评论*/
            $res=Db::name('goods_comment')
            ->where('id',$id)
            ->delete();
            if($res)
            {
                /*操作记录*/
                Message::admin_log(0,"后台删除评论id:".$id);
                $this->ajaxSuccess("操作成功！");
            }else{
                $this->ajaxError("操作失败！");
            }
        }

    }
}